// pages/teacher/mine/mineStu/mineStu.js
var app = getApp();
import {
  teacher_active
} from "../../../../asserts/js/common/barList";
import {
  post
} from "../../../../asserts/js/request";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classId: null,
    className: "",
    top: app.globalData.bottom + 'px',
    barList: teacher_active(1),
    title: {
      title1: "班级",
      title2: "学龄"
    },
    alter_show: false,
    tabObj: {
      tabList: [{
          name: "班级",
          code: "dance",
          active: true,
          cascadeObj: [],
          cascadeActive: 0,
          templete: "big-buttom"
        },
        {
          name: "学龄",
          code: "level",
          active: false,
          templete: "list-sort",
          cascadeObj: [{
              name: "全部",
              code: "",
              active: true
            },
            {
              name: "< 6个月",
              code: "0",
              active: false
            },
            {
              name: "6个月 ~ 1年",
              code: "1",
              active: false
            },
            {
              name: "1年 ~ 2年",
              code: "2",
              active: false
            },
            {
              name: "2年以上",
              code: "3",
              active: false
            }
          ]
        }
      ],
      activeIndex: 0
    },
    stuList: [],
    classId: [],
    studeyTime: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.classId = options.classId;
    this.data.className = options.className;
    console.log(options)
    this.setData({
      classId: options.classId,
      className: options.className
    });
    this.getData();
    //this.getAllClass();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function () {
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function () {
    this.setData({
      alter_show: false
    })
  },
  back: function () {
    wx.navigateBack({
      delta: 0,
    })
  },
  getData: function () {
    let this_ = this;

    post("queryStudent", {
      classId: this.data.classId,
      studentName: ""
    }).then(data => {
      console.log(data);
      this_.setData({
        stuList: data.studentInfo
      })
      wx.setStorageSync('subList', data.studentInfo.map(item => {
        item.active = false;
        item.studentList = item.studentList.map(el => {
          el.active = false;
          el.courseShow = false;
          el.courseList = [];
          return el;
        })
        return item;
      }));
    }).catch(err => {
      console.log(err);
    });
  },
  showStuCourses: function (e) {
    console.log(e.currentTarget.dataset.item)
    wx.setStorage({
      key: 'choosenStudent',
      data: {
        studentId: e.currentTarget.dataset.item.studentId,
        studentName: e.currentTarget.dataset.item.studentName,
        avatarUrl: e.currentTarget.dataset.item.avatarUrl
      }
    });
    wx.navigateTo({
      url: '/pages/teacher/myclass/teacherStuCourse/teacherStuCourse?classId=' +
        this.data.classId +
        '&studentId=' + e.currentTarget.dataset.item.studentId +
        '&studentName=' + e.currentTarget.dataset.item.studentName +
        '&className=' + this.data.className
    });
  }
})